package com.wfuhui.modules.goods.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wfuhui.common.annotation.AuthIgnore;
import com.wfuhui.common.utils.Query;
import com.wfuhui.common.utils.R;
import com.wfuhui.modules.goods.entity.GoodsEntity;
import com.wfuhui.modules.goods.service.GoodsService;

@RestController
@RequestMapping("/api/goods")
public class ApiGoodsController {
	
	@Autowired
	private GoodsService goodsService;
	
    @AuthIgnore
    @GetMapping("list")
    public R list(Integer page, Integer limit, Integer isRecommend, String goodsName, Integer categoryId){
    	Map<String, Object> params = new HashMap<String, Object>();
    	params.put("page", page);
    	params.put("limit", limit);
    	params.put("isRecommend", isRecommend);
    	params.put("goodsName", goodsName);
    	params.put("categoryId", categoryId);
    	params.put("status", 1);
    	Query query = new Query(params);
    	List<GoodsEntity> goodsList = goodsService.queryList(query);
        return R.ok().put("goodsList", goodsList);
    }
    
    @AuthIgnore
    @GetMapping("detail")
    public R detail(int id){
    	GoodsEntity goods = goodsService.queryObject(id);
    	return R.ok().put("goods", goods);
    }
    
    @AuthIgnore
    @GetMapping("getListByIds")
    public R getListByIds(int[] ids) {
    	Map<String, Object> params = new HashMap<String, Object>();
    	params.put("ids", ids);
    	List<GoodsEntity> goodsList = goodsService.queryList(params);
    	return R.ok().put("goodsList", goodsList);
    }
    
}
